﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using secondhand.L3object;
using System.Data;
using secondhand.L1database;

namespace secondhand.L2busslogic
{
    public class bookBL
    {
        public static bookOB Getmark()     //获取数据库中的大单条数据
        {
            string commandtext = "select * from book ";
            bookOB myword = new bookOB();       //数据库对象
            myword.book_name = "访问数据库不成功！";
            DataSet ds = null;
            ds = bookDB.GetItem(commandtext);
            if (ds == null)
            {
                return myword;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return myword;
            }

            int i = 0;


            myword.book_name = ds.Tables[0].Rows[i][1].ToString().Trim();
            myword.book_type = ds.Tables[0].Rows[i][2].ToString().Trim();
            myword.book_price = ds.Tables[0].Rows[i][3].ToString().Trim();
            myword.book_describe = ds.Tables[0].Rows[i][4].ToString().Trim();
            myword.book_picture = ds.Tables[0].Rows[i][5].ToString().Trim();
            myword.book_time = ds.Tables[0].Rows[i][6].ToString().Trim();
            myword.user_name = ds.Tables[0].Rows[i][7].ToString().Trim();
            myword.saler_name = ds.Tables[0].Rows[i][8].ToString().Trim();
            myword.receive_goods = ds.Tables[0].Rows[i][9].ToString().Trim();

            return myword;
        }
        public static bookOBList GetmarkAll()       //获取数据库中的所有记录
        {
            string commandtext = "select * from book";
            bookOBList tempList = null;
            tempList = new bookOBList();
            DataSet ds = null;
            ds = bookDB.GetItem(commandtext);
            if (ds == null)
            {
                return tempList;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return tempList;
            }

            int count = ds.Tables[0].Rows.Count;
            for (int i = 0; i < count; i++)
            {
                bookOB myword = new bookOB();

                myword.book_name = ds.Tables[0].Rows[i][1].ToString().Trim();
                myword.book_type = ds.Tables[0].Rows[i][2].ToString().Trim();
                myword.book_price = ds.Tables[0].Rows[i][3].ToString().Trim();
                myword.book_describe = ds.Tables[0].Rows[i][4].ToString().Trim();
                myword.book_picture = ds.Tables[0].Rows[i][5].ToString().Trim();
                myword.book_time = ds.Tables[0].Rows[i][6].ToString().Trim();
                myword.user_name = ds.Tables[0].Rows[i][7].ToString().Trim();
                myword.saler_name = ds.Tables[0].Rows[i][8].ToString().Trim();
                myword.receive_goods = ds.Tables[0].Rows[i][9].ToString().Trim();
                tempList.Insert(i, myword);
            }
            return tempList;
        }
        public static bool Addfill(bookOB myword)      //添加纪录
        {
            string ss = "INSERT INTO book (book_name,book_type,book_price,book_describe,book_picture,book_time,user_name,saler_name,receive_goods)VALUES('";
            ss = ss + myword.book_name.Trim() + "','";
            ss = ss + myword.book_type.Trim() + "','";
            ss = ss + myword.book_price.Trim() + "','";
            ss = ss + myword.book_describe.Trim() + "','";
            ss = ss + myword.book_picture.Trim() + "','";
            ss = ss + myword.book_time.Trim() + "','";
            ss = ss + myword.user_name.Trim() + "','";
            ss = ss + myword.saler_name.Trim() + "','";
            ss = ss + myword.receive_goods.Trim() + "')";

            return bookDB.AddDeleteItem(ss);
        }

        public static bookOB Getwordsingle(string nameq)      //按姓名查找
        {
            string commandtext = "select * from book where book_name='" + nameq.Trim() + "'";
            bookOB myword = new bookOB();
            myword.book_name = "访问数据库不成功！";
            DataSet ds = null;
            ds = bookDB.GetItem(commandtext);
            if (ds == null)
            {
                return myword;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return myword;
            }

            int i = 0;

            myword.ID = ds.Tables[0].Rows[i][0].ToString().Trim();
            myword.book_name = ds.Tables[0].Rows[i][1].ToString().Trim();
            myword.book_type = ds.Tables[0].Rows[i][2].ToString().Trim();
            myword.book_price = ds.Tables[0].Rows[i][3].ToString().Trim();
            myword.book_describe = ds.Tables[0].Rows[i][4].ToString().Trim();
            myword.book_picture = ds.Tables[0].Rows[i][5].ToString().Trim();
            myword.book_time = ds.Tables[0].Rows[i][6].ToString().Trim();
            myword.user_name = ds.Tables[0].Rows[i][7].ToString().Trim();
            myword.saler_name = ds.Tables[0].Rows[i][8].ToString().Trim();
            myword.receive_goods = ds.Tables[0].Rows[i][9].ToString().Trim();

            return myword;
        }

        public static bookOB Getwordsingle1(string salerName, string nameq)      //按姓名查找
        {

            string commandtext = "select * from book where user_name='" + salerName.Trim() + "'" + "and book_name='" + nameq.Trim() + "'";
            bookOB myword = new bookOB();
            myword.book_name = "访问数据库不成功！";
            DataSet ds = null;
            ds = goodsDB.GetItem(commandtext);
            if (ds == null)
            {
                return myword;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return myword;
            }

            int i = 0;

            myword.ID = ds.Tables[0].Rows[i][0].ToString().Trim();
            myword.book_name = ds.Tables[0].Rows[i][1].ToString().Trim();
            myword.book_type = ds.Tables[0].Rows[i][2].ToString().Trim();
            myword.book_price = ds.Tables[0].Rows[i][3].ToString().Trim();
            myword.book_describe = ds.Tables[0].Rows[i][4].ToString().Trim();
            myword.book_picture = ds.Tables[0].Rows[i][5].ToString().Trim();
            myword.book_time = ds.Tables[0].Rows[i][6].ToString().Trim();
            myword.user_name = ds.Tables[0].Rows[i][7].ToString().Trim();
            myword.saler_name = ds.Tables[0].Rows[i][8].ToString().Trim();
            myword.receive_goods = ds.Tables[0].Rows[i][9].ToString().Trim();

            return myword;
        }

        public static bool Savemark(bookOB myword)     //修改记录
        {
            string commandtext = "update book set  book_name='";
            commandtext = commandtext + myword.book_name.Trim() + "', book_type='";
            commandtext = commandtext + myword.book_type.Trim() + "',book_price='";
            commandtext = commandtext + myword.book_price.Trim() + "',book_describe='";
            commandtext = commandtext + myword.book_describe.Trim() + "',book_picture='";
            commandtext = commandtext + myword.book_picture.Trim() + "',book_time='";
            commandtext = commandtext + myword.book_time.Trim() + "',user_name='";
            commandtext = commandtext + myword.user_name.Trim() + "',saler_name='";
            commandtext = commandtext + myword.saler_name.Trim() + "',receive_goods='";
            commandtext = commandtext + myword.receive_goods.Trim() + "' where ID=";
            commandtext = commandtext + myword.ID.Trim();
            return bookDB.AddDeleteItem(commandtext);
        }
        public static bool deleteword(string name)      //删除记录
        {

            string ss = "delete from book where book_name='" + name.Trim() + "'";
            return bookDB.AddDeleteItem(ss);


        }




        public static bookOBList Getmark_All(string q_name)       //获取数据库中的所有记录
        {
            string commandtext = "select * from book where user_name = '" + q_name.ToString().Trim() + "'";
            bookOBList tempList = null;
            tempList = new bookOBList();
            DataSet ds = null;
            ds = bookDB.GetItem(commandtext);
            if (ds == null)
            {
                return tempList;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return tempList;
            }

            int count = ds.Tables[0].Rows.Count;
            for (int i = 0; i < count; i++)
            {
                bookOB myword = new bookOB();

                myword.book_name = ds.Tables[0].Rows[i][1].ToString().Trim();
                myword.book_type = ds.Tables[0].Rows[i][2].ToString().Trim();
                myword.book_price = ds.Tables[0].Rows[i][3].ToString().Trim();
                myword.book_describe = ds.Tables[0].Rows[i][4].ToString().Trim();
                myword.book_picture = ds.Tables[0].Rows[i][5].ToString().Trim();
                myword.book_time = ds.Tables[0].Rows[i][6].ToString().Trim();
                myword.user_name = ds.Tables[0].Rows[i][7].ToString().Trim();
                myword.saler_name = ds.Tables[0].Rows[i][8].ToString().Trim();
                myword.receive_goods = ds.Tables[0].Rows[i][9].ToString().Trim();

                tempList.Insert(i, myword);
            }
            return tempList;
        }



        public static bookOBList Getmark_All_1(string q_name)       //获取数据库中的所有记录
        {
            string commandtext = "select * from book where saler_name = '" + q_name.ToString().Trim() + "'";
            bookOBList tempList = null;
            tempList = new bookOBList();
            DataSet ds = null;
            ds = bookDB.GetItem(commandtext);
            if (ds == null)
            {
                return tempList;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return tempList;
            }

            int count = ds.Tables[0].Rows.Count;
            for (int i = 0; i < count; i++)
            {
                bookOB myword = new bookOB();

                myword.book_name = ds.Tables[0].Rows[i][1].ToString().Trim();
                myword.book_type = ds.Tables[0].Rows[i][2].ToString().Trim();
                myword.book_price = ds.Tables[0].Rows[i][3].ToString().Trim();
                myword.book_describe = ds.Tables[0].Rows[i][4].ToString().Trim();
                myword.book_picture = ds.Tables[0].Rows[i][5].ToString().Trim();
                myword.book_time = ds.Tables[0].Rows[i][6].ToString().Trim();
                myword.user_name = ds.Tables[0].Rows[i][7].ToString().Trim();
                myword.saler_name = ds.Tables[0].Rows[i][8].ToString().Trim();
                myword.receive_goods = ds.Tables[0].Rows[i][9].ToString().Trim();
                tempList.Insert(i, myword);
            }
            return tempList;
        }
    }
}